home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
drwscr
/
drwscr.txt
next >
Wrap
Text File
|
1992-09-20
|
17KB
|
640 lines
' DRWSCR08.TXT
' DrawScript Routines
' Version 0.8
' 9/19/92
'
' Jim McClure (76666,1303)
'
' Sorry about uploading this as TEXT. I'll PKZIP next time...
'
' These routines are designed to simplify the programming of a
' Print Preview capability for text-oriented reports. The routines
' record the sequence of Prints, Tabs, etc., for later
' playback to one or more objects (e.g., Printer object,
' picture control, etc.). The routines also provide pagination with
' header/footer control.
'
' That's the good news. Now for the bad news. I'm still struggling with
' finding a good way to scale the text output for screen display so that
' it matches printer output. Currently, a point size of 8 is used for
' screen display because of some problems with printing sizes < 8. I
' will upload a revised display strategy later. For now, just use a
' picture control that scrolls vert. and horiz. A point size of 8 is
' more easily readable anyway!
'
' WARNING!
' This code is still very much under development! I will be uploading
' revised versions periodically if there's enough interest. I will
' also try to upload an entire mini-project next, showing how to
' use the routines. In the meantime, EXPECT BUGS! Feel free to make
' enhancements, etc. (e.g., adding better line/box support would
' be nice). I'll be happy to share whatever improvements I make...
'
' But first I have to get some sleep! <g>
'
'
'----------------------------------
'Here is some example usage of the routines
'
'
'First, provide your own routine called "dsBoundaryPrint" to
' print headers and footers (boundaries) as needed. Your
' dsBoundaryPrint routine will be called as follows:
'
' Sub dsBoundaryPrint(Region as integer, PageNum as integer)
'
'In your routine, you can use dsPrint, dsTab, etc., calls to print
' a nice header (if Region = 1) or footer (if Region = 2) for
' your report. Just be sure to print the same # of lines that
' you specify in the dsNew() function below.
'
'Create a new draw script for output page size of 60 lines,
' with 5 lines reserved for the header and 5 lines reserved for the
' footer, using the base font "Helv" point size 12:
'
' hDS% = dsNew(60, 5, 5, "Helv", 12)
'
'Print a few things to it:
'
' dsPrintNL "Hello World!"
' dsTab 30
' dsPrintNL "This is indented!"
' dsFontUnderLine TRUE
' dsPrintNL "This is underlined!"
' dsFontUnderLine FALSE
' dsPrintAttr "This is also underlined!", "U" 'U = underline
' dsNL 'This finishes prior line
' dsLine 'This draws a simple separator line on the output
' (NOTE: The separator doesn't take up a "line" of output-- it leaves
' the print cursor where it is.)
'
'Ok, we're done formatting
' dsClose(hDS%)
'
'Find out how many pages were generated
' nPages = dsMaxPages()
'
'(Remember, each page will have the appropriate header/footer
' provided by your dsBoundaryPrint routine.)
'
'Play them all back to the printer, starting at page #1
' dsPlay hDS%, DummyControl, TRUE, 1, nPages 'TRUE=Send to printer
'
'Play one page of same report back to a picture box-- start at page #3 this time
' dsPlay hDS%, RealPictureControl, FALSE, 3, 1
'(Now, set up a scroll bar or set of buttons to keep calling
' dsPlay with a larger PageStart, or allow user to jump directly
' to page # by entering it)
'
'Ok, don't need this draw script anymore
' dsFree(hDS%)
'(If you don't do this, a temp file will be left behind!)
'
'GOOD LUCK!
' Jim
'----------------------------------
'This goes in your Global.Bas module
'DrawScript data structure
Type DrawScriptType
Alloc As Integer
FileNum As Integer
FileName As String
MaxLines As Integer
HeaderLines As Integer
FooterLines As Integer
CurLine As Integer
CurPage As Integer
MaxPages As Integer
End Type
'----------------------------------
'This can go in a module called DrawScrpt.Bas
'Allocate array of DrawScript structures
Const nDrawScripts = 5
Dim DrawScript(nDrawScripts) As DrawScriptType
'The following hold the 'current' DS
Dim dsCurrent As Integer
Dim dsFileNum As Integer
Dim dsMaxLines As Integer, dsHeaderLines As Integer, dsFooterLines As Integer
Dim dsCurLine As Integer
Dim dsInBoundary As Integer
Dim dsCurPage As Integer, dsMaxPageNum As Integer
'----------------------------------
'Here come the routines
Sub dsPrint (PrintString As String)
'Print a string to the current DS
'
'Process header/footer
If Not dsInBoundary Then
dsCheckBoundary
End If
'Print string
Print #dsFileNum, "PR " + PrintString
End Sub
Sub dsPlay (hDS As Integer, c As Control, ToPrinter As Integer, PageStart As Integer, NumPages As Integer)
'Replay draw script on output device
'Either the Printer object (if ToPrinter is true)
' or to the supplied control "c" (e.g., form, picture)
'Replay starts at PageStart (1st page = 1) and
'proceeds for NumPages pages
'
Dim InpString As String, Cmd As String, Arg As String
Dim FileNum As Integer, StopNow As Integer
Dim PageCount As Integer
'Get a file number for use
FileNum = FreeFile
'Open the file for processing
Open DrawScript(hDS).FileName For Input As #FileNum
'See to starting page
PageCount = 1
Do While (PageCount < PageStart) And (Not EOF(FileNum))
'Read each line from the file
Line Input #FileNum, InpString
'Increment page count
If Left$(InpString, 2) = "NP" Then
PageCount = PageCount + 1
End If
Loop
'Process file 'till end
StopNow = FALSE
Do While (Not EOF(FileNum)) And (Not StopNow)
'Read each line from the file
Line Input #FileNum, InpString
'Separate command from data
Cmd = Left$(InpString, 2)
If Len(InpString) > 3 Then
Arg = Right$(InpString, Len(InpString) - 3)
Else
Arg = ""
End If
'Depending on which command is present...
Select Case Cmd
Case "PR"
'Print a string
If ToPrinter Then
Printer.Print Arg;
Else
c.Print Arg;
End If
Case "NL"
'Start a new line
If ToPrinter Then
Printer.Print
Else
c.Print
End If
Case "TB"
'Tab to specified location
If ToPrinter Then
Printer.Print Tab(Val(Arg));
Else
c.Print Tab(Val(Arg));
End If
Case "LN"
'Draw separator line
If ToPrinter Then
Printer.Line -Step(Printer.ScaleWidth, 0)
Printer.CurrentX = 0
Else
c.Line -Step(c.Width, 0)
c.CurrentX = 0
End If
Case "FB"
'Set FontBold property
If ToPrinter Then
Printer.FontBold = Val(Arg)
Else
c.FontBold = Val(Arg)
End If
Case "FU"
'Set FontUnderline property
If ToPrinter Then
Printer.FontUnderline = Val(Arg)
Else
c.FontUnderline = Val(Arg)
End If
Case "FI"
'Set FontItalic property
If ToPrinter Then
Printer.FontItalic = Val(Arg)
Else
c.FontItalic = Val(Arg)
End If
Case "FS"
'Set FontStrikethru property
If ToPrinter Then
Printer.FontStrikethru = Val(Arg)
Else
c.FontStrikethru = Val(Arg)
End If
Case "FZ"
'Set FontSize property
If ToPrinter Then
Printer.FontSize = Val(Arg)
Else
'Scale font size for screen
c.FontSize = 8
End If
Case "FN"
'Set FontName property
If ToPrinter Then
Printer.FontName = Arg
Else
c.FontName = Arg
End If
Case "NP"
'Start new page
If ToPrinter Then
Printer.NewPage
End If
'Keep track of # of pages
PageCount = PageCount + 1
'See if we should quit
If (Not ToPrinter) Or (PageCount = PageStart + NumPages) Then
StopNow = TRUE
End If
End Select
Loop